package com.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.common.Result;
import com.pojo.dto.AdminAddGoodDto;
import com.pojo.dto.AdminUpdateDto;
import com.pojo.entity.Goods;
import com.pojo.entity.User;
import com.service.IAdminService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : 杨世博
 * @date: Created in 15:38 2023/6/9
 */
@RestController
@RequestMapping("/admin")
@Api(tags = "管理员接口")
@Slf4j
public class AdminController {

    @Autowired
    IAdminService adminService;

    @PostMapping("/goodsStatus")
    public Result<Boolean> goodsStatus(@RequestParam("goodsId")Integer goodsId, @RequestParam("goodsStatus")Boolean goodsStatus){
        Boolean b = adminService.goodsStatus(goodsId, goodsStatus);
        return Result.success();
    }

    @PostMapping("/addGoods")
    public Result<IPage<Goods>> addGoods(@RequestBody AdminAddGoodDto adminAddGoodDto){
        IPage<Goods> goods = adminService.addGoods(adminAddGoodDto);
        return Result.success(goods);
    }

    @PostMapping("/updateGoods")
    public Result<IPage<Goods>> updateGoods(@RequestBody Goods good){
        IPage<Goods> goods = adminService.updateGoods(good);
        return Result.success(goods);
    }

    @PostMapping("/deleteGoods")
    public Result<IPage<Goods>> deleteGoods(@RequestParam("goodsId")Integer goodsId){
        IPage<Goods> goods = adminService.deleteGoods(goodsId);
        return Result.success(goods);
    }

    @PostMapping("/getUser")
    public Result<IPage<User>> getUser(@RequestParam(value = "key", required = false)String key,
                                       @RequestParam("pageNum")Integer pageNum,
                                       @RequestParam("size")Integer size){
        IPage<User> users = adminService.getUser(key, pageNum, size);
        return Result.success(users);
    }

    @PostMapping("/updateUser")
    public Result<IPage<User>> updateUser(@RequestBody AdminUpdateDto adminUpdateDto){
        IPage<User> users = adminService.updateUser(adminUpdateDto);
        return Result.success(users);
    }

    @PostMapping("/deleteUser")
    public Result<IPage<User>> deleteUser(@RequestParam("uid")Integer uid){
        IPage<User> users = adminService.deleteUser(uid);
        return Result.success(users);
    }

    @PostMapping("/getGoods")
    public Result<IPage<Goods>> getGoods(@RequestParam(value = "key", required = false)String key,
                                         @RequestParam("pageNum")Integer pageNum,
                                         @RequestParam("size")Integer size){
        IPage<Goods> goods = adminService.getGoods(key, pageNum, size);
        return Result.success(goods);
    }
}
